package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.Student;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpData() {
        List<Map> mapList = empMapper.getEmpData();
        List<Object> jobList = mapList.stream().map(map -> map.get("job")).collect(Collectors.toList());
        List<Object> dataList = mapList.stream().map(map -> map.get("total")).collect(Collectors.toList());
        JobOption jobOption = new JobOption(jobList,dataList);

        return jobOption;
    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    @Override
    public ClazzOption getStudentCountData() {
        List<Map> mapList = studentMapper.getStudentCountData();
        List<Object> clazzList = mapList.stream().map(map -> map.get("clazz")).collect(Collectors.toList());
        List<Object> dataList = mapList.stream().map(map -> map.get("total")).collect(Collectors.toList());
        ClazzOption clazzOption = new ClazzOption(clazzList,dataList);
        return clazzOption;
    }

    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }
}
